package cn.codeforfun.config;

import cn.codeforfun.interceptor.resolver.WxCallbackInterceptor;
import cn.codeforfun.interceptor.resolver.WxMsgInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;
import java.util.List;

@Configuration
public class MVCConfig extends WebMvcConfigurerAdapter {

  @Resource
  private WxMsgInterceptor wxMsgInterceptor;

  @Bean
  public WxCallbackInterceptor getWeChatInterceptorResolver() {
    return new WxCallbackInterceptor();
  }

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(getWeChatInterceptorResolver()).addPathPatterns("/callback");
  }

  @Override
  public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
    argumentResolvers.add(wxMsgInterceptor);
  }
}
